﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CalibrationLibrary
{
    class RankAccordingTo
    {
        public static void Rank(ref List<double> values, ref List<double> probabilities)
        {
            if (values.Count != probabilities.Count) throw new System.Exception("values.Count != probabilities.Count");

            List<double> ranked_values = new List<double>();
            List<double> ranked_probabilities = new List<double>();

            for (int c = 0; c < probabilities.Count;c++ )
            {

                int a = 0;
                for (a = 0; a < ranked_probabilities.Count; a++)
                {
                    if (ranked_probabilities[a] < probabilities[c])
                    {
                        ranked_values.Insert(a, values[c]);
                        ranked_probabilities.Insert(a, probabilities[c]);
                        break;
                    }
                }
                if (a == ranked_probabilities.Count)
                {
                    ranked_probabilities.Add(probabilities[c]);
                    ranked_values.Add(values[c]);
                }

            }

            probabilities = ranked_probabilities;
            values = ranked_values;

           
        
        }
    }
}
